<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="${model.packageName}.dao.${model.entityName}Mapper">
	
	<resultMap type="${model.packageName}.entity.${model.entityName}" id="${model.entityName}Map">
		<id column="c_id" jdbcType="INTEGER" property="id"/>
		<#list model.columns as field>
		<result column="${field.name}" jdbcType="${field.typeDB}" property="${field.javaName}"/>
		</#list>
	</resultMap>
	
	<select id="findList" parameterType="hashmap" resultMap="${model.entityName}Map">
		select t.*
		<include refid="findSql"/>
	</select>

    <select id="findOne" parameterType="hashmap" resultMap="${model.entityName}Map">
        select t.*
        <include refid="findSql"/>
    </select>

	<sql id="findSql">
		from ${model.tableName} t 
        <where>
        	<if test="id != null ">and t.c_id = ${r'#'}{id, jdbcType=INTEGER}</if>
        </where>
	</sql>
	
	<select id="findById" parameterType="Integer" resultMap="${model.entityName}Map">
		select t.* from ${model.tableName} t where t.c_id = ${r'#'}{id, jdbcType=INTEGER}
	</select>
	
	<insert id="addOne" parameterType="${model.packageName}.entity.${model.entityName}" useGeneratedKeys="true" keyProperty="id" >
        <#--<selectKey keyProperty="id" resultType="int" order="BEFORE">-->
            <#--select common_sequence.nextval from dual-->
        <#--</selectKey>-->

		insert into ${model.tableName}
        	(
    			C_ID,
	        	<#list model.columns as field>
        		${field.name}<#if field_has_next>,</#if>
	        	</#list>
        	)  
            values
            (
            	${r'#'}{id, jdbcType=INTEGER},
            	<#list model.columns as field>
				${r'#'}{${field.javaName}, jdbcType=${field.typeDB}} <#if field_has_next>,</#if>
	        	</#list>
            )  
    </insert>
    
    <update id="updateOne" parameterType="${model.packageName}.entity.${model.entityName}" >
        update ${model.tableName} set 
        	C_ID = ${r'#'}{id, jdbcType=INTEGER},
        <#list model.columns as field>
        	${field.name} = ${r'#'}{${field.javaName}, jdbcType=${field.typeDB}}<#if field_has_next>,</#if>
        </#list>
        where c_id =  ${r'#'}{id, jdbcType=INTEGER}
    </update>
    
    <delete id="delById" parameterType="Integer">
        delete from ${model.tableName} where c_id = ${r'#'}{id, jdbcType=INTEGER}
	</delete>
	
</mapper>
